package com.ruoyi.web.controller.gym;

import com.ny.domain.EquipmentDO;
import com.ny.dto.CreateGroup;
import com.ny.dto.DeleteGroup;
import com.ny.dto.EquipmentDTO;
import com.ny.dto.EquipmentMaintenanceDTO;
import com.ny.dto.RestResult;
import com.ny.dto.UpdateGroup;
import com.ny.query.EquipmentQuery;
import com.ny.query.QueryGroup;
import com.ny.service.EquipmentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.lang.Boolean;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 器材管理模块
 *
 * @author MSI-NB
 * @date 2025-03-08 13:14:38
 */
@Api("器材管理模块")
@RequestMapping("equipment")
@RestController
public class EquipmentController extends BaseController {

    @Autowired
    private EquipmentService equipmentService;

    /**
     * 查询所有器材
     */
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ApiOperation("查询所有器材")
    public TableDataInfo queryPageList(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize){
        List<EquipmentDO> equipmentDOList = equipmentService.findPageList(pageNum, pageSize);
        return getDataTable(equipmentDOList);
    }

    /**
     * 添加器材
     *
     * @param equipmentDTO 器材管理DTO
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ApiOperation("添加器材")
    @ResponseBody
    public RestResult<Boolean> addEquipment(@RequestBody @Validated(CreateGroup.class) EquipmentDTO equipmentDTO) {
        Boolean result = equipmentService.addEquipment(equipmentDTO);
        return RestResult.success(result);
    }

    /**
     * 删除器材
     *
     * @param equipmentDTO 器材管理DTO
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
    @ApiOperation("删除器材")
    @ResponseBody
    public RestResult<Boolean> deleteEquipment(@RequestBody @Validated(DeleteGroup.class) EquipmentDTO equipmentDTO) {
        Boolean result = equipmentService.deleteEquipment(equipmentDTO);
        return RestResult.success(result);
    }

    /**
     * 更新器材信息
     *
     * @param equipmentDTO 器材管理DTO
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.PUT)
    @ApiOperation("更新器材信息")
    @ResponseBody
    public RestResult<Boolean> updateEquipment(@RequestBody @Validated(UpdateGroup.class) EquipmentDTO equipmentDTO) {
        Boolean result = equipmentService.updateEquipment(equipmentDTO);
        return RestResult.success(result);
    }

    /**
     * 查询单个器材详情
     *
     * @param equipmentQuery 器材查询条件
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @ApiOperation("查询单个器材详情")
    public RestResult<EquipmentDO> infoEquipment(@Validated(QueryGroup.class) EquipmentQuery equipmentQuery) {
        EquipmentDO result = equipmentService.infoEquipment(equipmentQuery);
        return RestResult.success(result);
    }

    /**
     * 添加器材维护记录
     *
     * @param equipmentMaintenanceDTO 器材维护管理DTO
     * @return
     */
    @RequestMapping(value = "/maintenance/add", method = RequestMethod.POST)
    @ApiOperation("添加器材维护记录")
    @ResponseBody
    public RestResult<Boolean> addMaintenance(@RequestBody @Validated(CreateGroup.class) EquipmentMaintenanceDTO equipmentMaintenanceDTO) {
        Boolean result = equipmentService.addMaintenance(equipmentMaintenanceDTO);
        return RestResult.success(result);
    }

    /**
     * 删除器材维护记录
     *
     * @param equipmentMaintenanceDTO 器材维护管理DTO
     * @return
     */
    @RequestMapping(value = "/maintenance/delete", method = RequestMethod.DELETE)
    @ApiOperation("删除器材维护记录")
    @ResponseBody
    public RestResult<Boolean> deleteMaintenance(@RequestBody @Validated(DeleteGroup.class) EquipmentMaintenanceDTO equipmentMaintenanceDTO) {
        Boolean result = equipmentService.deleteMaintenance(equipmentMaintenanceDTO);
        return RestResult.success(result);
    }

    /**
     * 更新器材维护记录
     *
     * @param equipmentMaintenanceDTO 器材维护管理DTO
     * @return
     */
    @RequestMapping(value = "/maintenance/update", method = RequestMethod.PUT)
    @ApiOperation("更新器材维护记录")
    @ResponseBody
    public RestResult<Boolean> updateMaintenance(@RequestBody @Validated(UpdateGroup.class) EquipmentMaintenanceDTO equipmentMaintenanceDTO) {
        Boolean result = equipmentService.updateMaintenance(equipmentMaintenanceDTO);
        return RestResult.success(result);
    }
}
